package com.editso.haier.controller.user;

import com.editso.haier.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/assets")
public class ResourceController {

    private FileService fileService;

    @Autowired
    public void setFileService(FileService fileService) {
        this.fileService = fileService;
    }

    @GetMapping(path = "/{file}")
    public Object get(@PathVariable(name = "file") String fileName,
                      @RequestParam String path,
                      @RequestParam(defaultValue = "application/octet-stream", name = "type") String contentType){
        return fileService.download(path, fileName, contentType);
    }
}
